<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="软件包,rpm,yum," />





  <link rel="alternate" href="/atom.xml" title="大牙的杂货铺" type="application/atom+xml" />






<meta name="description" content="RPM什么是rpmRPM是RedHat Package Manager（RedHat软件包管理工具）。它工作于R e d Hat Linux以及其它Linux系统，成为了Linux中公认的软件包管理标准。红帽子软件公司鼓励其他厂商来了解R PM并在自己的产品中使用它。R PM的发布基于GPL协议。随着R PM在各种发行">
<meta name="keywords" content="软件包,rpm,yum">
<meta property="og:type" content="article">
<meta property="og:title" content="软件包的管理">
<meta property="og:url" content="http://linuxgeeks.github.io/2015/06/16/2015-06-15-244110-软件包的管理/index.html">
<meta property="og:site_name" content="大牙的杂货铺">
<meta property="og:description" content="RPM什么是rpmRPM是RedHat Package Manager（RedHat软件包管理工具）。它工作于R e d Hat Linux以及其它Linux系统，成为了Linux中公认的软件包管理标准。红帽子软件公司鼓励其他厂商来了解R PM并在自己的产品中使用它。R PM的发布基于GPL协议。随着R PM在各种发行版本的广泛使用，如今R PM的全称是R PM Pack ageManage r。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-01-30T14:14:02.491Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="软件包的管理">
<meta name="twitter:description" content="RPM什么是rpmRPM是RedHat Package Manager（RedHat软件包管理工具）。它工作于R e d Hat Linux以及其它Linux系统，成为了Linux中公认的软件包管理标准。红帽子软件公司鼓励其他厂商来了解R PM并在自己的产品中使用它。R PM的发布基于GPL协议。随着R PM在各种发行版本的广泛使用，如今R PM的全称是R PM Pack ageManage r。">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://linuxgeeks.github.io/2015/06/16/2015-06-15-244110-软件包的管理/"/>





  <title>软件包的管理 | 大牙的杂货铺</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
	
	<a href="https://github.com/mengdaya"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">大牙的杂货铺</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://linuxgeeks.github.io/2015/06/16/2015-06-15-244110-软件包的管理/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="孟庆宇">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="大牙的杂货铺">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">软件包的管理</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-06-16T00:41:10+08:00">
                2015-06-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/软件管理/" itemprop="url" rel="index">
                    <span itemprop="name">软件管理</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"> 本文总阅读量</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  3,822
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  15
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="RPM"><a href="#RPM" class="headerlink" title="RPM"></a>RPM</h1><h2 id="什么是rpm"><a href="#什么是rpm" class="headerlink" title="什么是rpm"></a>什么是rpm</h2><p>RPM是RedHat Package Manager（RedHat软件包管理工具）。它工作于R e d Hat Linux以及<br>其它Linux系统，成为了Linux中公认的软件包管理标准。红帽子软件公司鼓励其他厂商来了解R PM并在自己的产品中使用它。R PM的发布基于GPL协议。随着R PM在各种发行版本的广泛使用，如今R PM的全称是R PM Pack age<br>Manage r。</p>
<h2 id="rpm包管理的用途"><a href="#rpm包管理的用途" class="headerlink" title="rpm包管理的用途"></a>rpm包管理的用途</h2><p>1、可以安装、删除、升级和管理软件；当然也支持在线安装和升级软件；<br>2、通过RPM包管理能知道软件包包含哪些文件，也能知道系统中的某个文件属于哪个软件包；<br>3、可以在查询系统中的软件包是否安装以及其版本；<br>4、作为开发者可以把自己的程序打包为RPM 包发布；<br>5、软件包签名GPG和MD5的导入、验证和签名发布<br>6、依赖性的检查，查看是否有软件包由于不兼容而扰乱了系统；</p>
<h2 id="RPM-包的命名方式"><a href="#RPM-包的命名方式" class="headerlink" title="RPM 包的命名方式"></a>RPM 包的命名方式</h2><p>以 httpd-2.2.15-39.el6.centos.x86_64.rpm 为例，</p>
<ul>
<li>httpd 表示软件名</li>
<li>2.2.15 表示主版本号，次版本号，发行版本号分别是2，2，15</li>
<li>39.el6.centos 表示 RPM 包的修订号和 OS 信息</li>
<li>x86_64 表示此软件包适用的平台，常见的有i386，i586，x86_64 等</li>
</ul>
<h2 id="RPM包管理命令的使用"><a href="#RPM包管理命令的使用" class="headerlink" title="RPM包管理命令的使用"></a>RPM包管理命令的使用</h2><h4 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm &#123;-i|--install&#125; [install-options] PACKAGE_FILE1..</span><br></pre></td></tr></table></figure>
<ul>
<li>安装时可以使用 -h 以#的个数显示安装进度，一个#表示2%的进度，使用 -v 显示详细安装信息</li>
<li>--test 可以用于测试安装是否能够成功，而不实际安装</li>
<li>在安装过程中，可能遇到软件包的依赖问题，而需要先安装其他软件包，--nodeps 忽略依赖强制安装，但是这样安装的软件包通常也会因为依赖缺失而无法正常工作</li>
<li>如果需要重新安装并覆盖原有的文件，可以使用 --replacepkgs 选项</li>
<li>使用 --force 可以进行强制覆盖安装，它等同于--replacepkgs, --replacefiles, 和 --oldpackage</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh /media/cdrom/CentOS/elinks-0.11.1-5.1.el5.i386.rpm</span><br><span class="line">rpm -ivh http://centos.candishosting.com.cn/5/os/i386/CentOS/elinks-0.11.1-5.1.el5.i386.rpm</span><br></pre></td></tr></table></figure>
<h4 id="升级或安装"><a href="#升级或安装" class="headerlink" title="升级或安装"></a>升级或安装</h4><ul>
<li>如果不知道一个软件包是否已经安装，并希望如果已经安装那么升级次软件包，使用 -U 选项。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm &#123;-U|--upgrade&#125; [install-options] PACKAGE_FILE ...</span><br></pre></td></tr></table></figure>
<ul>
<li>如果仅仅希望升级软件包，使用 -F 选项</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm &#123;-F|--freshen&#125; [install-options] PACKAGE_FILE ...</span><br></pre></td></tr></table></figure>
<ul>
<li>升级软件包和安装软件包一样，可以使用 --test、--nodeps、--force 等选项。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># 安装并升级 zsh 软件包</span><br><span class="line">[root@localhost rpm]# rpm -ivh zsh-4.3.10-7.el6.x86_64.rpm</span><br><span class="line">Preparing...                ########################################### [100%]</span><br><span class="line">1:zsh                       ########################################### [100%]</span><br><span class="line">[root@localhost rpm]# rpm -Uvh zsh-4.3.10-9.el6.x86_64.rpm</span><br><span class="line">Preparing...                ########################################### [100%]</span><br><span class="line">1:zsh                       ########################################### [100%]</span><br></pre></td></tr></table></figure>
<ul>
<li>如果想要将软件包降级到旧版本，使用 –oldpackage 选项</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost rpm]# rpm -Uvh --oldpackage zsh-4.3.10-7.el6.x86_64.rpm</span><br><span class="line">Preparing...                ########################################### [100%]</span><br><span class="line">1:zsh                       ########################################### [100%]</span><br></pre></td></tr></table></figure>
<ul>
<li>在升级软件包时，原来软件包的配置文件可能已经被修改，升级时，新版本的文件不会将老版本的配置文件覆盖，而是将新版本的配置文件加上 <code>.rpmnew</code> 后缀后保存。</li>
</ul>
<p><strong>注意：</strong>内核也是软件包，但是不建议直接对内核进行升级。多版本内核可以并存，因此建议执行安装操作</p>
<h4 id="卸载"><a href="#卸载" class="headerlink" title="卸载"></a>卸载</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm &#123;-e|--erase&#125; [--allmatches] [--nodeps] [--test] PACKAGE_NAME ...</span><br></pre></td></tr></table></figure>
<ul>
<li>通常使用 rpm -e PACKAGE_ANEM 即可简单卸载一个软件包</li>
<li>使用 --nodeps 忽略依赖关系--test 测试卸载。--allmatches 表示如果一个程序包同时安装多个版本，则次选项一次全部卸载之</li>
<li>如果卸载正常，不会输出任何信息。</li>
</ul>
<p><strong>注意：</strong>如果程序包的配置文件安装后曾被修改，卸载时，此文件通常不会被删除，而是被重命名为 .rpmsave 后缀后留存。</p>
<h4 id="查询"><a href="#查询" class="headerlink" title="查询"></a>查询</h4><ul>
<li>查询使用 -q 选项，可以检查安装的所有包，还可以查看某包的详细信息。</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm &#123;-q|--query&#125; [select-options] [query-options]</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">rpm -q zsh</span><br><span class="line"># 查询某包是否已经安装</span><br><span class="line"></span><br><span class="line">rpm -qa</span><br><span class="line"># 查询安装的所有包 </span><br><span class="line"></span><br><span class="line">rpm -qp nmap-5.51-4.el6.x86_64</span><br><span class="line"># 查询未安装包信息</span><br><span class="line"># 查询未安装包的信息指定的是 RPM 包的文件名而不是某个包的软件名。</span><br><span class="line"></span><br><span class="line">rpm -qi bash</span><br><span class="line"># 查询安装包包的简要说明信息</span><br><span class="line"></span><br><span class="line">rpm -ql zsh</span><br><span class="line"># 查询软件包安装的文件列表</span><br><span class="line"></span><br><span class="line">rpm -qf /etc/ssh/sshd_config</span><br><span class="line"># 查询某文件是哪个包安装生成的</span><br><span class="line"></span><br><span class="line">rpm -qc openssh-server</span><br><span class="line"># 查看软件包安装后生成的所有配置文件</span><br><span class="line"></span><br><span class="line">rpm -qd nmap</span><br><span class="line"># 查看软件包安装后生成的所有说明文件和帮助文件</span><br><span class="line"></span><br><span class="line">rpm -q --changelog nmap</span><br><span class="line"># 查看软件包制作时随版本变化的 changelog 信息</span><br><span class="line"></span><br><span class="line">rpm -q --requires nmap</span><br><span class="line"># 查看软件包所需的依赖</span><br><span class="line"></span><br><span class="line">rpm -q --scripts zsh</span><br><span class="line"># 查看软件包安装或卸载时执行的脚本</span><br><span class="line"># 脚本分四类</span><br><span class="line"># preinstall 安装前脚本</span><br><span class="line"># postinstall 安装后脚本</span><br><span class="line"># preuninstall 卸载前脚本</span><br><span class="line"># postuninstall 卸载后脚本</span><br></pre></td></tr></table></figure>
<h4 id="检验"><a href="#检验" class="headerlink" title="检验"></a>检验</h4><p>查询软件包安装之后的文件是否发生了改变</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm &#123;-V|--verify&#125; [select-options] [verify-options]</span><br></pre></td></tr></table></figure>
<p>检验时使用了多个位表示文件的多个属性是否发生了变化：</p>
<p>S 文件大小<br>M 文件权限<br>5 文件摘要信息（通常是 MD5 码）<br>D 设备文件的主/次设备号<br>L 软链接变化<br>U 属主<br>G 属组<br>T 文件的 mtime<br>P caPabilities</p>
<h4 id="程序包的合法性验证"><a href="#程序包的合法性验证" class="headerlink" title="程序包的合法性验证"></a>程序包的合法性验证</h4><ul>
<li>在软件包制作时，为了防止软件包被人修改植入后门，制作者可以使用自己私钥对软件包进行数字签名，安装者就可以使用公钥验证软件包的合法性。同时还可以使用摘要算法提取软件包的摘要信息用于验证软件包的完整性。</li>
<li><p>通常，RHEL 系的安装光盘中包含有用于验证其软件包合法性的公钥文件。</p>
</li>
<li><p>导入公钥</p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm --import /path/to/RPM-GPG-KEY-FILE</span><br></pre></td></tr></table></figure>
<ul>
<li>验证合法性</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm &#123;-K|--checksig&#125; PACKAGE_FILE</span><br></pre></td></tr></table></figure>
<h4 id="RPM-管理器的数据库"><a href="#RPM-管理器的数据库" class="headerlink" title="RPM 管理器的数据库"></a>RPM 管理器的数据库</h4><p>每次安装 rpm 包时，rpm 系统会将一些元信息存储在它的数据库中，使用 rpm -q 命令查询软件包的相关信息时将会查询这些数据库，数据库文件位于 /var/lib/rpm 目录中。如果 RPM 的数据库损坏，将会导致一些 RPM 数据丢失，一些功能将无法正常使用。</p>
<h4 id="重建数据库"><a href="#重建数据库" class="headerlink" title="重建数据库"></a>重建数据库</h4><p>如果 RPM 的数据库损坏，首先可以尝试重建它，如果无法重建，那么需要重新初始化数据库。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm --rebuilddb 表示重建数据库</span><br></pre></td></tr></table></figure>
<ul>
<li>这个命令会从已安装的软件包提取信息重建数据库，它从 /var/lib/rpm/Packages 这个文件中提取信息，其他所有的数据库文件都可以由这个文件重建。如果 RPM 的数据库是完好的，这个命令不会重建，而是对数据库中未使用的条目进行空间回收。</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm --initdb 创建一个新的 RPM 数据</span><br></pre></td></tr></table></figure>
<ul>
<li>如果已经没有其他别的办法了，–initdb 会创建一个新的空的 RPM 数据库。由于新建的数据库是空的，不要万不得已不要使用这个命令。</li>
</ul>
<h1 id="yum"><a href="#yum" class="headerlink" title="yum"></a>yum</h1><h2 id="为什么使用yum"><a href="#为什么使用yum" class="headerlink" title="为什么使用yum"></a>为什么使用yum</h2><p>Linux系统维护中令管理员很头疼的就是软件包之间的依赖性了，往往是你要安装A软件，但是编译的时候告诉你X软件安装之前需要B软件，而当你安装Y软件的时候，又告诉你需要Z库了，好不容易安装好Z库，发现版本还有问题等。由于历史原因，R PM软件包管理系统对软件之间的依存关系没有内部定义，造成安装RPM软件时经常出现令人无法理解的软件依赖问题。其实开源社区早就对这个问题尝试进行解决了，不同的发行版推出了各自的工具，比如Yellow Dog的YUM（Yellowdog Updater, Modified），De bian的APT(Advance d Pack aging Tool)等。开发这些工具的目的都是为了要解决安装RPM时的依赖性问题，而不是额外再建立一套安装模式。</p>
<h2 id="什么是yum"><a href="#什么是yum" class="headerlink" title="什么是yum"></a>什么是yum</h2><ul>
<li>yum（全称为 Yellow dog Updater, Modified）是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。</li>
<li>基於RPM包管理，能够从指定的服务器自动下载RPM包并且安装，可以自动处理依赖性关系，并且一次安装所有依赖的软体包，无须繁琐地一次次下载、安装。</li>
<li><p>YUM基于RPM包管理工具，能够从指定的源（服务器，本地目录等）自动下载目标RPM包并且安装，可以自动处理依赖性关系并进行下载、安装，无须繁琐地手动下载、安装每一个需要的依赖包。</p>
</li>
<li><p>yum的特点</p>
<ul>
<li>自动解决包的倚赖性问题能更方便的添加/删除/更新R PM包</li>
<li>便于管理大量系统的更新问题</li>
<li>可以同时配置多个资源库(Re pository)</li>
<li>简洁的配置文件(/etc/yum .conf)</li>
<li>保持与RPM数据库的一致性</li>
<li>有一个比较详细的log，可以查看何时升级安装了什么软件包等</li>
<li>使用方便</li>
</ul>
</li>
</ul>
<h2 id="yum客户端"><a href="#yum客户端" class="headerlink" title="yum客户端"></a>yum客户端</h2><ul>
<li>配置文件：指定各可用的yum仓库</li>
<li>缓存元数据：yum会到各可用yum仓库获取元数据，并缓存至本地</li>
<li>分析元数据：根据具体的操作请求完成元数据分析，可能包括依赖关系、文件列表等信息</li>
<li>执行具体操作</li>
<li>客户端配置文件指定对服务器配置文件<ul>
<li>ftp ftp://server/path/to/repo</li>
<li>http <a href="http://server/path/to/repo" target="_blank" rel="noopener">http://server/path/to/repo</a></li>
<li>nfs  nfs://servr/nfs_path</li>
<li>file file:///path/to/path</li>
</ul>
</li>
</ul>
<h2 id="仓库配置"><a href="#仓库配置" class="headerlink" title="仓库配置"></a>仓库配置</h2><ul>
<li>要使用yum管理应用程序，首先得配置其可用的yum仓库，保存在配置文件中。</li>
<li><p>配置文件格式：由两段组成。</p>
<ul>
<li>/etc/yum.conf： [main]，主配置段</li>
<li>/etc/yum.repo.d/*.repo： [repo]，仓库配置段</li>
</ul>
</li>
<li><p>配置repo</p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[repositoryid]</span><br><span class="line">name=Some name <span class="keyword">for</span> this repository</span><br><span class="line">baseurl=url://server1/path/to/repository/</span><br><span class="line">url://server2/path/to/repository/</span><br><span class="line">url://server3/path/to/repository/</span><br><span class="line">mirrorlist=url://path/to/mirrorlist/repository/</span><br><span class="line">enabled=0/1</span><br><span class="line">gpgcheck=0/1</span><br><span class="line">gpgkey=A URL pointing to the ASCII-armoured GPG key file <span class="keyword">for</span> the repository</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">repositoryid    <span class="comment"># 指定一个仓库</span></span><br><span class="line">name            <span class="comment"># 指定易读的仓库名称</span></span><br><span class="line">baseurl         <span class="comment"># 指定本仓库的URL，可以是如下的几种类型# </span></span><br><span class="line">    http            <span class="comment"># 指定远程HTTP协议的源</span></span><br><span class="line">    ftp             <span class="comment"># 指定远程FTP协议的源</span></span><br><span class="line">    file            <span class="comment"># 本地镜像或NFS挂装文件系统</span></span><br><span class="line">enabled         <span class="comment"># 指定是否使用本仓库，默认值为1，即可用</span></span><br><span class="line">gpgcheck        <span class="comment"># 指定是否检查软件包的GPG签名</span></span><br><span class="line">gpgkey          <span class="comment"># 公钥地址，可以是本地，也可以是服务器端路径</span></span><br><span class="line">cost            <span class="comment"># 定义此仓库开销，默认为1000</span></span><br></pre></td></tr></table></figure>
<h2 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h2><ul>
<li>安装</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">yum install             <span class="comment"># 全部安装</span></span><br><span class="line">yum install package1    <span class="comment"># 安装指定的安装包package1，手动禁止检查来源及完整性：--nogpgcheck</span></span><br><span class="line">yum reinstall package1  <span class="comment"># 重新安装指定的安装包package1</span></span><br><span class="line">yum groupinsall group1  <span class="comment"># 安装程序组group1</span></span><br></pre></td></tr></table></figure>
<ul>
<li>更新和升级</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">yum check-update        <span class="comment"># 检查可升级的包</span></span><br><span class="line">yum update              <span class="comment"># 全部更新</span></span><br><span class="line">yum update package1     <span class="comment"># 更新指定程序包package1，要升级到指定版本要带版本号如nmap-5.51</span></span><br><span class="line">yum upgrade package1    <span class="comment"># 升级指定程序包package1</span></span><br><span class="line">yum groupupdate group1  <span class="comment"># 升级程序组group1</span></span><br><span class="line">yum downgrade package1  <span class="comment"># 降级指定程序包package1</span></span><br></pre></td></tr></table></figure>
<ul>
<li>查找和显示</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">yum info package1       <span class="comment"># 显示安装包信息package1</span></span><br><span class="line">yum list                <span class="comment"># [all|installed（已安装过的）|available(可用)];显示所有已经安装和可以安装的程序包</span></span><br><span class="line">yum list package1       <span class="comment"># 显示指定程序包安装情况package1</span></span><br><span class="line">yum info                <span class="comment"># 显示包的详细信息</span></span><br><span class="line">yum grouplist           <span class="comment"># 列出所有的包组</span></span><br><span class="line">yum groupinfo group1    <span class="comment"># 显示程序组group1信息</span></span><br><span class="line">yum search string       <span class="comment"># 根据关键字string查找安装包</span></span><br><span class="line">yum deplist package1    <span class="comment"># 查看程序package1依赖情况</span></span><br><span class="line">yum whatprovides /etc/shadow    <span class="comment"># 查看/etc/shadow是由哪个包提供的</span></span><br><span class="line">yum provides /etc/shadow        <span class="comment"># 查看/etc/shadow是由哪个包提供的</span></span><br><span class="line">yum <span class="built_in">history</span>             <span class="comment"># 查看yum的命令历史</span></span><br></pre></td></tr></table></figure>
<ul>
<li>删除和卸载</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum remove|erase package1   <span class="comment"># 移除|卸载程序包package1，依赖的包也会被卸载</span></span><br><span class="line">yum groupremove group1      <span class="comment"># 删除程序组group1</span></span><br></pre></td></tr></table></figure>
<ul>
<li>清除缓存</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">yum clean packages      <span class="comment"># 清除缓存目录/var/cache/yum 下的软件包</span></span><br><span class="line">yum clean headers       <span class="comment"># 清除缓存目录/var/cache/yum 下的 headers</span></span><br><span class="line">yum clean oldheaders    <span class="comment"># 清除缓存目录/var/cache/yum 下旧的 headers</span></span><br><span class="line">yum clean;yum clean all <span class="comment"># = yum clean packages; yum clean oldheaders)</span></span><br></pre></td></tr></table></figure>
<h2 id="yum配置文件中可用的宏"><a href="#yum配置文件中可用的宏" class="headerlink" title="yum配置文件中可用的宏"></a>yum配置文件中可用的宏</h2><ul>
<li>$releasever：程序的版本<ul>
<li>对Yum而言指的是redhat-relrase版本。</li>
<li>只替换为主版本号，如Redhat6.5 则替换为6</li>
</ul>
</li>
<li>$arch:系统架构 </li>
<li>$basharch:系统基本架构，如i686，i586等的基本架构为i386</li>
<li>$YUM0-9:在系统定义的环境变量，可以在yum中使用</li>
</ul>
<h2 id="CentOS的镜像站点"><a href="#CentOS的镜像站点" class="headerlink" title="CentOS的镜像站点"></a>CentOS的镜像站点</h2><p>镜像站点的第一级目录是发行版本号，如 3、4、5 等</p>
<ul>
<li>搜狐开源镜像站：<a href="http://mirrors.sohu.com/" target="_blank" rel="noopener">http://mirrors.sohu.com/</a></li>
<li>网易开源镜像站：<a href="http://mirrors.163.com/" target="_blank" rel="noopener">http://mirrors.163.com/</a></li>
<li><p>北京理工大学：</p>
<ul>
<li><a href="http://mirror.bit.edu.cn" target="_blank" rel="noopener">http://mirror.bit.edu.cn</a>  (IPv4 only)</li>
<li><a href="http://mirror.bit6.edu.cn" target="_blank" rel="noopener">http://mirror.bit6.edu.cn</a> (IPv6 only)</li>
</ul>
</li>
<li><p>清华大学：</p>
<ul>
<li><a href="http://mirrors.tuna.tsinghua.edu.cn/" target="_blank" rel="noopener">http://mirrors.tuna.tsinghua.edu.cn/</a> (IPv4+IPv6)</li>
<li><a href="http://mirrors.6.tuna.tsinghua.edu.cn/" target="_blank" rel="noopener">http://mirrors.6.tuna.tsinghua.edu.cn/</a> (IPv6 only)</li>
<li><a href="http://mirrors.4.tuna.tsinghua.edu.cn/" target="_blank" rel="noopener">http://mirrors.4.tuna.tsinghua.edu.cn/</a> (IPv4 only)</li>
</ul>
</li>
<li><p>天津大学：<a href="http://mirror.tju.edu.cn/" target="_blank" rel="noopener">http://mirror.tju.edu.cn/</a></p>
</li>
<li><p>中国科学技术大学：</p>
<ul>
<li><a href="http://mirrors.ustc.edu.cn/" target="_blank" rel="noopener">http://mirrors.ustc.edu.cn/</a> (IPv4+IPv6)</li>
<li><a href="http://mirrors4.ustc.edu.cn/" target="_blank" rel="noopener">http://mirrors4.ustc.edu.cn/</a></li>
<li><a href="http://mirrors6.ustc.edu.cn/" target="_blank" rel="noopener">http://mirrors6.ustc.edu.cn/</a></li>
</ul>
</li>
</ul>
<h1 id="源码包"><a href="#源码包" class="headerlink" title="源码包"></a>源码包</h1><h4 id="linux源码包与RPM包的区别"><a href="#linux源码包与RPM包的区别" class="headerlink" title="linux源码包与RPM包的区别"></a>linux源码包与RPM包的区别</h4><ul>
<li>安装之前<ul>
<li>源码包是开源的，比RPM包安装更自由，但是它安装更慢，更容易报错</li>
<li>RPM包是经过编译的，不能看到源代码，但是它安装更快，报错更容易解决，只有依赖性问题</li>
</ul>
</li>
<li>安装之后<ul>
<li>RPM包不需要指定安装位置，它会安装到系统默认位置</li>
<li>源码包是人为手工设置</li>
</ul>
</li>
</ul>
<h4 id="源码包编译安装基本步骤"><a href="#源码包编译安装基本步骤" class="headerlink" title="源码包编译安装基本步骤"></a>源码包编译安装基本步骤</h4><blockquote>
<p><strong>注意：</strong>源码包编译安装前提是准备开发环境(编译环境)</p>
<ul>
<li>若系统为Centos 5，开发包组为”Development Tools“和”DeveLopment Libraries“</li>
<li>若系统为centos 6，常用的开发包为”Development tools“和”Server Platform Development”</li>
</ul>
</blockquote>
<ol>
<li>拿到源代码，并解压<br> tar -xf package-version.tar.{gz|bz2|xz}<br><strong>注意：</strong>展开后的目录通常为package-version</li>
<li>切换至源码目录中<br> cd package-version</li>
<li>执行configure脚本<br> ./configure</li>
<li>编译<br> make</li>
<li>安装<br> make install</li>
<li>头文件输出给系统、创建库文件链接、二进制可执行文件环境变量、导出man文件</li>
</ol>
<h4 id="configure脚本的通用功能-需要定义的配置"><a href="#configure脚本的通用功能-需要定义的配置" class="headerlink" title="configure脚本的通用功能(需要定义的配置)"></a>configure脚本的通用功能(需要定义的配置)</h4><ul>
<li>指定安装路径<ul>
<li>--prefix=前缀，用于指定安装路径</li>
<li>--sysconfdir=/etc/package_name</li>
</ul>
</li>
<li>指定启动/禁用的特性<ul>
<li>--enable-feature</li>
<li>--disable-fecture</li>
</ul>
</li>
<li>指定所依赖功能、程序或文件  <ul>
<li>--with-function：启用某功能</li>
<li>--without-function： 禁用某功能</li>
</ul>
</li>
</ul>
<p>不同的程序，其configure不尽相同，应获取帮助信息</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./configure --<span class="built_in">help</span></span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>有钱任性，请我吃包辣条</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="孟庆宇 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="孟庆宇 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    孟庆宇
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://linuxgeeks.github.io/2015/06/16/2015-06-15-244110-软件包的管理/" title="软件包的管理">http://linuxgeeks.github.io/2015/06/16/2015-06-15-244110-软件包的管理/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/软件包/" rel="tag"><i class="fa fa-tag"></i> 软件包</a>
          
            <a href="/tags/rpm/" rel="tag"><i class="fa fa-tag"></i> rpm</a>
          
            <a href="/tags/yum/" rel="tag"><i class="fa fa-tag"></i> yum</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/03/28/2015-03-28-094910-文件路径搜索命令整理/" rel="next" title="文件路径搜索命令整理">
                <i class="fa fa-chevron-left"></i> 文件路径搜索命令整理
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/06/25/2015-06-25-223610-vi与vim入门指北/" rel="prev" title="vi与vim入门指北">
                vi与vim入门指北 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
  <div class="bdsharebuttonbox">
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
    <a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网"></a>
    <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
    <a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧"></a>
    <a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a>
    <a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
    <a href="#" class="bds_more" data-cmd="more"></a>
    <a class="bds_count" data-cmd="count"></a>
  </div>
  <script>
    window._bd_share_config = {
      "common": {
        "bdText": "",
        "bdMini": "2",
        "bdMiniList": false,
        "bdPic": ""
      },
      "share": {
        "bdSize": "16",
        "bdStyle": "0"
      },
      "image": {
        "viewList": ["tsina", "douban", "sqq", "qzone", "weixin", "twi", "fbook"],
        "viewText": "分享到：",
        "viewSize": "16"
      }
    }
  </script>

<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          


          
  


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="孟庆宇" />
            
              <p class="site-author-name" itemprop="name">孟庆宇</p>
              <p class="site-description motion-element" itemprop="description">书山有路勤为径，学海无涯苦作舟</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">109</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">23</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">56</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/mengdaya" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:yourname@gmail.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            
          </div>

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-globe"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.ibm.com/developerworks/cn/" title="IBM developerWorks" target="_blank">IBM developerWorks</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://iissnan.com/progit/" title="Pro Git" target="_blank">Pro Git</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.freeoa.net/index/" title="freeOA" target="_blank">freeOA</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.ttlsa.com/" title="运维生存时间" target="_blank">运维生存时间</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.361way.com/" title="运维之路" target="_blank">运维之路</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.yiibai.com/" title="易百教程" target="_blank">易百教程</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.centoscn.com/" title="CentOS中文站" target="_blank">CentOS中文站</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.linuxprobe.com/" title="Linux就该这么学" target="_blank">Linux就该这么学</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.netingcn.com/" title="网络进行时" target="_blank">网络进行时</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.ruanyifeng.com/blog/" title="阮一峰的网络日志" target="_blank">阮一峰的网络日志</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.liaoxuefeng.com" title="廖雪峰的官方网站" target="_blank">廖雪峰的官方网站</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yihui.name/cn/" title="谢益辉的博客" target="_blank">谢益辉的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://coolshell.cn" title="酷壳" target="_blank">酷壳</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#RPM"><span class="nav-number">1.</span> <span class="nav-text">RPM</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是rpm"><span class="nav-number">1.1.</span> <span class="nav-text">什么是rpm</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#rpm包管理的用途"><span class="nav-number">1.2.</span> <span class="nav-text">rpm包管理的用途</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#RPM-包的命名方式"><span class="nav-number">1.3.</span> <span class="nav-text">RPM 包的命名方式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#RPM包管理命令的使用"><span class="nav-number">1.4.</span> <span class="nav-text">RPM包管理命令的使用</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#安装"><span class="nav-number">1.4.0.1.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#升级或安装"><span class="nav-number">1.4.0.2.</span> <span class="nav-text">升级或安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#卸载"><span class="nav-number">1.4.0.3.</span> <span class="nav-text">卸载</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查询"><span class="nav-number">1.4.0.4.</span> <span class="nav-text">查询</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#检验"><span class="nav-number">1.4.0.5.</span> <span class="nav-text">检验</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#程序包的合法性验证"><span class="nav-number">1.4.0.6.</span> <span class="nav-text">程序包的合法性验证</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#RPM-管理器的数据库"><span class="nav-number">1.4.0.7.</span> <span class="nav-text">RPM 管理器的数据库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#重建数据库"><span class="nav-number">1.4.0.8.</span> <span class="nav-text">重建数据库</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#yum"><span class="nav-number">2.</span> <span class="nav-text">yum</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么使用yum"><span class="nav-number">2.1.</span> <span class="nav-text">为什么使用yum</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是yum"><span class="nav-number">2.2.</span> <span class="nav-text">什么是yum</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#yum客户端"><span class="nav-number">2.3.</span> <span class="nav-text">yum客户端</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#仓库配置"><span class="nav-number">2.4.</span> <span class="nav-text">仓库配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常用命令"><span class="nav-number">2.5.</span> <span class="nav-text">常用命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#yum配置文件中可用的宏"><span class="nav-number">2.6.</span> <span class="nav-text">yum配置文件中可用的宏</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#CentOS的镜像站点"><span class="nav-number">2.7.</span> <span class="nav-text">CentOS的镜像站点</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#源码包"><span class="nav-number">3.</span> <span class="nav-text">源码包</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#linux源码包与RPM包的区别"><span class="nav-number">3.0.0.1.</span> <span class="nav-text">linux源码包与RPM包的区别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#源码包编译安装基本步骤"><span class="nav-number">3.0.0.2.</span> <span class="nav-text">源码包编译安装基本步骤</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#configure脚本的通用功能-需要定义的配置"><span class="nav-number">3.0.0.3.</span> <span class="nav-text">configure脚本的通用功能(需要定义的配置)</span></a></li></ol></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">文章总结于网络，转载请注明出处</span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">本站访客</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">本站总访问量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="true"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  








  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

  

</body>
</html>
